package com.gome.ocean.server.oracle.positioner;

import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.gome.ocean.server.oracle.exception.YuGongException;

/**
 * 数据库记录
 * 
 * @author haqiaolong
 *
 */
public class MysqlRecordPositioner extends MemoryRecordPositioner implements
		RecordPositioner {

	private ScheduledExecutorService executor;
	private long period = 1; //每分钟记录一次

	public void start() {
		super.start();
		executor = Executors.newScheduledThreadPool(1);
		// 启动定时工作任务
		executor.scheduleAtFixedRate(new Runnable() {
			public void run() {
				try {
					
				} catch (Throwable e) {
					// ignore
					logger.error("period update position failed!", e);
				}
			}
		}, period, period, TimeUnit.MINUTES);
	}

	public void stop() {
		super.stop();
		flushDataToMysql();
		executor.shutdownNow();
	}
	
	/**
	 * 强制更新position
	 */
	private void flushDataToMysql() {
        if (position != null) {
//            try {
//            	
//            } catch (IOException e) {
//                throw new YuGongException(e);
//            }
        }
    }
}
